home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / CC_C / 0924.ZIP / SINPLOT < prev    next >
Text File  |  1988-01-10  |  2KB  |  82 lines

  1.  
  2.  
  3. /* TEST    PLOTTING PROGRAM FOR SIN */
  4. /* Requires ANSI.SYS loaded for    graphics */
  5.  
  6.  
  7. #include smio.h
  8.  
  9. main() {  static int i,    j;
  10.  
  11.       scrgraf();
  12.  
  13.       putstr ("Demonstration SIN plot.\n");
  14.  
  15.       for (i = 0; i    < 360; i += 30)
  16.       sinplot ( (float) i);
  17.  
  18.       for (i = 0; i    < 300; i++ )
  19.       for (j = 0; j    < 300; j++ ) j;
  20.  
  21.       scrtxt();
  22.     }
  23.  
  24. sinplot    (off) float off;
  25.      {      float    f, sin();  f = -300.;
  26.       plot ( 20, (int) (100. + 90. * sin (f    + off)), 1);
  27.       while    ( (f +=    3.) <= 300. )
  28.       lplot    ( (int)    (320. +    f),
  29.           (int)    (100. +    90. * sin (f + off)), 1); }
  30.  
  31.  
  32. /* PLOTTING ROUTINES */
  33.  
  34. scrgraf()  { putstr ("\33[=6h"); }   /*    Graphics screen    set and    clear    */
  35. scrtxt()   { putstr ("\33[=2h"); }   /*    Text screen set     */
  36.  
  37. /* Line    plotting - draw    from last position to x, y */
  38. lplot (x, y, t)    int x, y, t;
  39.      {    int xi,    yi, mx,    mn, dx,    dy, mt,    cc, i;
  40.     xi = yi    = 1;
  41.     if ( (dx = x - _grx) < 0 ) { dx    = -dx; xi = -1;    }
  42.     if ( (dy = y - _gry) < 0 ) { dy    = -dy; yi = -1;    }
  43.     mt = (dx > dy);    mx = mt    ? dx : dy; mn =    mt ? dy    : dx;
  44.     for ( cc = mx >> 1, i =    0; i < mx; i++ )
  45.     {  if (    (cc += mn) > mx    )
  46.        { plot ( _grx + xi, _gry + yi, t); cc -= mx;    }
  47.        else    plot ( _grx + (mt ? xi : 0), _gry + (mt    ? 0 : yi), t); } }
  48.  
  49. /* Plot    a single pixel on 640 x    200 screen -
  50.    t = 0: move only, t = 1: plot,
  51.    t = 2: xorplot,   t = -1: unplot */
  52.  
  53. plot (x, y, t) int x, y, t;
  54.      {    static int ad, mm;
  55.     _grx = x; _gry = y;
  56.     if (!t)    return;
  57.     if ( _grx < 0 || _grx >= 640 ) return;
  58.     if ( _gry < 0 || _gry >= 200 ) return;
  59.     ad = 80    * (_gry    >> 1) +    (_grx >> 3)
  60.          + ( (_gry & 0x01) ? 0x2000    : 0 );
  61.     mm = 0x80 >> (_grx & 0x07);
  62.  
  63.     if (t<0)
  64.     /*  epoke (epeek(0xB800, ad) & ~mm, 0xB800, ad); */
  65.     inline ( 0x06, 0xBB, 0xB800,
  66.          0x8E, 0xC3, 0x8B, 0x1E, &ad,
  67.          0xA0, &mm,  0x34, 0xFF, 0x26, 0x20, 0x07, 0x07);
  68.     else if    (t==1)
  69.     /*  epoke (epeek(0xB800, ad) | mm, 0xB800, ad);    */
  70.     inline ( 0x06, 0xBB, 0xB800,
  71.          0x8E, 0xC3, 0x8B, 0x1E, &ad,
  72.          0xA0, &mm,  0x26, 0x08, 0x07, 0x07 );
  73.     else
  74.     /*  epoke (epeek(0xB800, ad) ^ mm, 0xB800, ad);     */
  75.     inline ( 0x06, 0xBB, 0xB800,
  76.          0x8E, 0xC3, 0x8B, 0x1E, &ad,
  77.          0xA0, &mm,  0x26, 0x30, 0x07, 0x07 ); }
  78.  
  79.  
  80. #include ?smfps.lib
  81. #include ?smio.lib
  82.